package com.ly.cloud.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.ClassroomDto;
import com.ly.cloud.dto.TeachBuildingDto;
import com.ly.cloud.service.ClassroomService;
import com.ly.cloud.service.TeachBuildingService;
import com.ly.cloud.vo.ClassroomTypeVo;
import com.ly.cloud.vo.ClassroomVo;
import com.ly.cloud.vo.TeachBuildingTyVo;
import com.ly.cloud.vo.TeachBuildingVo;
import com.ly.cloud.web.utils.WebResponse;

/**
 * Description:教学场地Controller
 * @author luhuacong
 * @date: 2018年12月13日
 */
@RestController
@RequestMapping("/teachPlace")
public class TeachingPlaceController {

	@Resource
	private TeachBuildingService teachBuildingService;
	@Resource
	private ClassroomService classroomService;
	
	/**
	 * Method Name:insertTeachBuild
	 * Description:添加教学楼信息
	 * @param dto 条件封装对象
	 * @param loginUserName 登录用户
	 * @return  WebResponse<Boolean>
	 * @author luhuacong
	 * @date: 2018/12/13
	 */
	@RequestMapping(value="/insertTeachBuild",method = RequestMethod.POST)
	public WebResponse<Boolean> insertTeachBuild(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody TeachBuildingDto dto) {
		boolean rs = teachBuildingService.insert(dto, loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * Description:添加教室信息
	 * @param 条件封装对象
	 * @return  WebResponse<Boolean>
	 * @param loginUserName 登录用户
	 * @author luhuacong
	 * @date: 2018/12/14
	 */
	@RequestMapping(value="/insertClassroom",method = RequestMethod.POST)
	public WebResponse<Boolean> insertDetail(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody ClassroomDto dto) {
		boolean rs = classroomService.insertClassroom(dto, loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/** 
	 * Method Name: deleteTeachBuild
	 * Description:  
	 * 根据id删除教学楼信息
	 * @param jxlh 教学楼编号 
	 * @author LuHuaCong
	 * @date: 2018年12月13日
	 */
	@RequestMapping(value="/deleteTeachBuild/{jxlh}",method = RequestMethod.POST)
	public WebResponse<Boolean> deleteTeachBuild(@PathVariable("jxlh") String jxlh) {
		boolean rs = teachBuildingService.deleteByid(jxlh);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/** 
	 * Method Name: deleteClassroomByid
	 * Description:  
	 * 根据id删除教室信息
	 * @param jsh 教室编号
	 * @author LuHuaCong
	 * @date: 2018年12月14日
	 */
	@RequestMapping(value="/deleteClassroomById/{jsh}",method = RequestMethod.POST)
	public WebResponse<Boolean> deleteClassroomById(@PathVariable("jsh") String jsh) {
		boolean rs = classroomService.deleteClassroomByid(jsh);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/** 
	 * Method Name: deleteClassroomByIds
	 * Description:  
	 * 批量删除教室信息
	 * @param ids 教室编号集合
	 * @author LuHuaCong
	 * @date: 2018年12月14日
	 */
	@RequestMapping(value="/deleteClassroomByIds",method = RequestMethod.POST)
	public WebResponse<Integer> deleteClassroomByIds(@RequestBody List<String> jshList) {
		Integer rs = classroomService.deleteClassroomByIds(jshList);
		return new WebResponse<Integer>().success(rs);
	}
	
	/**
	 * Method Name:updateTeachBuild
	 * Description:修改教学楼信息
	 * @param 条件封装对象
	 * @param loginUserName 登录用户
	 * @return  WebResponse<Boolean>
	 * @author luhuacong
	 * @date: 2018/12/13
	 */
	@RequestMapping(value="/updateTeachBuild",method = RequestMethod.POST)
	public WebResponse<Boolean> updateTeachBuild(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody TeachBuildingDto dto) {
		boolean rs = teachBuildingService.update(dto, loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/** 
	 * Method Name: updateClassroom
	 * Description:  
	 * 修改教室信息
	 * @param dto
	 * @param loginUserName 登录用户
	 * @author LuHuaCong
	 * @date: 2018年12月14日
	 */
	@RequestMapping(value="/updateClassroom",method = RequestMethod.POST)
	public WebResponse<Boolean> updateClassroom(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody ClassroomDto dto) {
		boolean rs = classroomService.updateClassroom(dto, loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/** 
	 * Description:  查询所有教学楼信息
	 * @param pageNum 当前页
	 * @param pageSize 每页显示条数
	 * @return List<TeachBuildingVo>
	 * @author LuHuaCong
	 * @date: 2018年12月14日
	 */
	@RequestMapping(value = "/selectAllTb", method = RequestMethod.GET)
	public  WebResponse<PageInfo<TeachBuildingVo>> selectAllTb(@RequestParam int pageNum, @RequestParam int pageSize){
		Page<TeachBuildingVo> page = teachBuildingService.selectAllTb(new Page<TeachBuildingVo>(pageNum, pageSize));
		return new WebResponse<PageInfo<TeachBuildingVo>>().success(PageInfo.toPageInfo(page));
		
	}
	
	/** 
	 * Description:  根据校区编号和教学楼名称查询教学楼信息
	 * @param page 
	 * @param xqdm 校区编号
	 * @param xqmc 教学楼名称
	 * @return List<TeachBuildingVo>
	 * @author LuHuaCong
	 * @date: 2018年12月13日
	 */
	@RequestMapping(value = "/selectTeachBuildList", method = RequestMethod.GET)
	public  WebResponse<PageInfo<TeachBuildingVo>> selectTeachBuildList(@RequestParam int pageNum, @RequestParam int pageSize,@RequestParam(required=false) String xqdm,@RequestParam(required=false) String jxlmc){
		Page<TeachBuildingVo> page = teachBuildingService.selectTeachBuildingList(new Page<TeachBuildingVo>(pageNum, pageSize), xqdm, jxlmc);
		return new WebResponse<PageInfo<TeachBuildingVo>>().success(PageInfo.toPageInfo(page));		
	}
	
	/** 
	 * Description:  查询教学楼编号和名称，用于下拉列表
	 * @param xqdm 校区编号 
	 * @return List<TeachBuildingVo>
	 * @author LuHuaCong
	 * @date: 2018年12月14日
	 */
	@RequestMapping(value = "/selectTeachBuildTy", method = RequestMethod.GET)
	public  WebResponse<List<TeachBuildingTyVo>> selectTeachBuildTy(@RequestParam(required=false) String xqdm){
		List<TeachBuildingTyVo> list = teachBuildingService.selectTeachBuildTy(xqdm);
		return new WebResponse<List<TeachBuildingTyVo>>().success(list);		
	}
	
	/** 
	 * Method Name:selectJsListByCon
	 * Description:  根据条件 查询教室信息
	 * @param pageNum	当前页
	 * @param pageSize	每页显示条数
	 * @param dto 
	 * @return Page<ClassroomVo>
	 * @author LuHuaCong
	 * @date: 2018年12月14日
	 */
    @RequestMapping(value = "selectJsListByCon", method = RequestMethod.POST)
    public WebResponse<PageInfo<ClassroomVo>> selectJsListByCon(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ClassroomDto dto){
        Page<ClassroomVo> page = classroomService.selectByCondition(new Page<ClassroomVo>(pageNum, pageSize), dto);
        return new WebResponse<PageInfo<ClassroomVo>>().success(PageInfo.toPageInfo(page));
    }
    
    /** 
	 * Description:教室类型下拉列表
	 * @return 教室类型信息
	 * @author LuHuaCong
	 * @date: 2018年12月17日
	 */
    @RequestMapping(value = "selectClaType", method = RequestMethod.GET)
    public WebResponse<List<ClassroomTypeVo>> selectClaType(){
        List<ClassroomTypeVo> list = classroomService.selectClaType();
        return new WebResponse<List<ClassroomTypeVo>>().success(list);
    }
}
